#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int findSubstringInWraproundString(string s) {
        int n = s.size();
        vector<int> dp(n, 1);
        for (int i = 1; i < n; i++) {
            if (s[i] - 1 == s[i - 1] || s[i] == 'a' && s[i - 1] == 'z') {
                dp[i] = dp[i - 1] + 1;
            }
        }
        int hashi[26] = { 0 };
        for (int i = 0; i < n; i++) {
            hashi[s[i] - 'a'] = max(hashi[s[i] - 'a'], dp[i]);
        }
        int sum = 0;
        for (auto e : hashi) {
            sum += e;
        }
        return sum;
    }
};